package cn.git.init;

import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/** 
 * @description: 初始化设置ip hostname等信息通用类
 * @program: bank-credit-sy
 * @author: lixuchun
 * @create: 2024-01-03
 */
@Component
public class InitLogIpHost implements EnvironmentAware {

    private static Environment environment;


    @PostConstruct
    public void initIpHostEnvInfo() {
        // 设置 applicationName
        System.setProperty("applicationName", environment.getProperty("spring.application.name"));
        // 设置 ip
        System.setProperty("ip", NetUtil.getLocalIp());
        // 设置 hostname
        System.setProperty("hostName", NetUtil.getLocalHostName());
    }

    /**
     * Set the {@code Environment} that this component runs in.
     *
     * @param environment
     */
    @Override
    public void setEnvironment(Environment environment) {
        InitLogIpHost.environment = environment;
    }
}
